package com.leet.code.lcof;

public class Code65 {
    public static void main(String[] args) {

//        System.out.println(Integer.toBinaryString(0xffffffff));
//        System.out.println(Integer.toBinaryString(0x80000000));

        int a = -1231231231, b = 123123123;
        int sum = new Code65().add(a, b);

        println(Integer.toBinaryString(a));
        println(Integer.toBinaryString(b));
        println(Integer.toBinaryString(sum));

        System.out.println(sum == (a + b));


    }

    public int add(int a, int b) {
        while (b != 0) {
            int c = (a & b) << 1;//进位和
            a = a ^ b;//非进位和
            b = c;
        }
        return a;
    }


    public static void println(String i) {
        System.out.println(String.format("%1$32s", i));

    }
}
